package com.itHuangTao.tank.ui;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.scene.SubScene;
import com.itHuangTao.tank.Config;
import com.itHuangTao.tank.TankApp;
import javafx.animation.PauseTransition;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.util.Duration;

public class SucceedScene extends SubScene {

    private PauseTransition pt;

    public SucceedScene() {
        //设置文本
        Text text = new Text("Victory！");
        //设置文本颜色
        text.setFill(Color.RED);
        //设置字体样式
        text.setFont(new Font("斜体字",100));

        StackPane pane = new StackPane(text);
        //设置窗口大小
        pane.setPrefSize(FXGL.getAppWidth(), FXGL.getAppHeight());
        //设置背景色(蓝色)
        pane.setStyle("-fx-background-color: blue");
        //加入组件
        getContentRoot().getChildren().add(pane);

        //暂停动画
        pt = new PauseTransition(Duration.seconds(2));
        //暂停完毕后进入下一关
        pt.setOnFinished(event -> {
            if (FXGL.geti("level") < Config.MAX_LEVEL) {
                //关闭当前场景
                FXGL.getSceneService().popSubScene();
                //关卡进入下一关
                FXGL.inc("level", 1);
                //执行游戏初始化
                FXGL.<TankApp>getAppCast().startLevel();
            } else {
                //添加文字说明
                FXGL.getNotificationService().pushNotification("Victory！恭喜你闯过全部关卡\n更多玩法等待请最新开发~~~");
                //回到主菜单
                FXGL.getGameController().gotoMainMenu();
            }
        });
    }

    @Override
    public void onCreate() {
        pt.play();
    }
}
